<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Color Match Game</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Arial', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #1a1a2e, #16213e);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            color: white;
        }

        .game-container {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 2rem;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
            text-align: center;
            max-width: 500px;
            width: 90%;
        }

        .game-header {
            margin-bottom: 2rem;
        }

        .game-title {
            font-size: 2.5rem;
            margin-bottom: 1rem;
            background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            animation: titleGlow 2s infinite alternate;
        }

        @keyframes titleGlow {
            from {
                text-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
            }

            to {
                text-shadow: 0 0 20px rgba(78, 205, 196, 0.5);
            }
        }

        .score-container {
            display: flex;
            justify-content: space-between;
            margin-bottom: 2rem;
            font-size: 1.2rem;
        }

        .game-board {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 1rem;
            margin-bottom: 2rem;
        }

        .color-tile {
            aspect-ratio: 1;
            border-radius: 10px;
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
        }

        .color-tile:hover {
            transform: scale(1.05);
            box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
        }

        .controls {
            display: flex;
            justify-content: center;
            gap: 1rem;
        }

        .btn {
            padding: 0.8rem 1.5rem;
            border: none;
            border-radius: 25px;
            background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
            color: white;
            font-size: 1rem;
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
        }

        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        }

        .timer {
            font-size: 1.5rem;
            margin-bottom: 1rem;
        }

        .message {
            margin-top: 1rem;
            font-size: 1.2rem;
            min-height: 1.5em;
        }

        @media (max-width: 500px) {
            .game-container {
                padding: 1rem;
            }

            .game-title {
                font-size: 2rem;
            }

            .game-board {
                gap: 0.5rem;
            }
        }
    </style>
</head>

<body>
    <div class="game-container">
        <div class="game-header">
            <h1 class="game-title">Color Match</h1>
            <div class="score-container">
                <div>Score: <span id="score">0</span></div>
                <div>High Score: <span id="highScore">0</span></div>
            </div>
            <div class="timer">Time: <span id="time">60</span>s</div>
        </div>
        <div class="game-board" id="gameBoard"></div>
        <div class="message" id="message"></div>
        <div class="controls">
            <button class="btn" id="startBtn">Start Game</button>
            <button class="btn" id="resetBtn">Reset</button>
        </div>
    </div>

    <script>
        const gameBoard = document.getElementById('gameBoard');
        const scoreElement = document.getElementById('score');
        const highScoreElement = document.getElementById('highScore');
        const timeElement = document.getElementById('time');
        const messageElement = document.getElementById('message');
        const startBtn = document.getElementById('startBtn');
        const resetBtn = document.getElementById('resetBtn');

        let score = 0;
        let highScore = localStorage.getItem('highScore') || 0;
        let timeLeft = 60;
        let gameInterval;
        let timerInterval;
        let isGameActive = false;
        let targetColor = null;

        const colors = [
            '#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4',
            '#FFEEAD', '#D4A5A5', '#9B59B6', '#3498DB'
        ];

        function createGameBoard() {
            gameBoard.innerHTML = '';
            const shuffledColors = [...colors, ...colors].sort(() => Math.random() - 0.5);

            shuffledColors.forEach((color, index) => {
                const tile = document.createElement('div');
                tile.className = 'color-tile';
                tile.style.backgroundColor = color;
                tile.dataset.color = color;
                tile.dataset.index = index;
                tile.addEventListener('click', () => handleTileClick(tile));
                gameBoard.appendChild(tile);
            });
        }

        function startGame() {
            if (isGameActive) return;

            isGameActive = true;
            score = 0;
            timeLeft = 60;
            scoreElement.textContent = score;
            timeElement.textContent = timeLeft;
            messageElement.textContent = '';
            startBtn.disabled = true;

            createGameBoard();

            timerInterval = setInterval(() => {
                timeLeft--;
                timeElement.textContent = timeLeft;

                if (timeLeft <= 0) {
                    endGame();
                }
            }, 1000);
        }

        function endGame() {
            isGameActive = false;
            clearInterval(timerInterval);
            startBtn.disabled = false;

            if (score > highScore) {
                highScore = score;
                localStorage.setItem('highScore', highScore);
                highScoreElement.textContent = highScore;
            }

            messageElement.textContent = `Game Over! Final Score: ${score}`;
        }

        function handleTileClick(tile) {
            if (!isGameActive) return;

            if (!targetColor) {
                targetColor = tile.dataset.color;
                tile.style.border = '3px solid white';
            } else {
                if (tile.dataset.color === targetColor) {
                    score += 10;
                    scoreElement.textContent = score;
                    tile.style.opacity = '0';
                    document.querySelector(`[data-color="${targetColor}"][style*="border"]`).style.opacity = '0';
                    messageElement.textContent = 'Match! +10 points';
                } else {
                    score = Math.max(0, score - 5);
                    scoreElement.textContent = score;
                    messageElement.textContent = 'Wrong! -5 points';
                }

                document.querySelector(`[data-color="${targetColor}"][style*="border"]`).style.border = 'none';
                targetColor = null;
            }
        }

        startBtn.addEventListener('click', startGame);
        resetBtn.addEventListener('click', () => {
            endGame();
            createGameBoard();
        });

        highScoreElement.textContent = highScore;
    </script>
</body>

</html>